/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "Hogshead.Common.h"
#include <d3d11.h>
#include "../EnumConstDeclarations/RenderingBufferUsage.h"

namespace Hogshead
{
	namespace DX11Rendering
	{
		class RenderingTextureBuffer
		{
		public:
			RenderingTextureBuffer(void);
			~RenderingTextureBuffer(void);

			RenderingTextureBuffer(const RenderingTextureBuffer& in_other);

			RenderingTextureBuffer& operator=(const RenderingTextureBuffer& in_other);

			/**
			* Called by any class using this data structure to create it from a block of xml.
			*
			* @param in_xml A block of XML that contains the data for this class.
			**/
			void readXML( const String& in_xml);

			/**
			* Called to create a RenderingTextureBuffer. 
			*
			* @param in_texture2D_desc The 2D texture description.
			* @param in_rtv_desc The Render Target View description. May be set to NULL;
			* @param in_dsv_desc The Depth Stencil View description. May be set to NULL;
			* @param in_srv_desc The Shader Resource View description. May be set to NULL;
			**/
			void build(const D3D11_TEXTURE2D_DESC& in_texture2D_desc, const D3D11_RENDER_TARGET_VIEW_DESC* in_rtv_desc,
					 const D3D11_DEPTH_STENCIL_VIEW_DESC* in_dsv_desc, const D3D11_SHADER_RESOURCE_VIEW_DESC* in_srv_desc, const char* in_opt_name = NULL, int in_opt_size = 0);

			/**
			* Called by any class using this data structure to release all used DirectX Resources.
			**/
			void finalize();

			ID3D11RenderTargetView* renderTargetView();
			ID3D11DepthStencilView* depthStencilView();
			ID3D11ShaderResourceView* shaderResourceView();
			

		private:
			//the data we hold onto to interperate this buffer.
			ID3D11ShaderResourceView* _srv;
			ID3D11RenderTargetView* _rtv;
			ID3D11DepthStencilView* _dsv;

			//binding flags
			RenderingBufferUsage _current_binding;

			//used to map strings relevant to this class to dx 11 enum values
			static HashTable<String, DXGI_FORMAT>* _lookup;
			
			DXGI_FORMAT nameToValue(const String& in_name);
		};
	}
}
